package com.guigu.xiaowenbo.controller;

import com.guigu.aop.OpLog;
import com.guigu.liuzhireng.pojo.Account;
import com.guigu.xiaowenbo.pojo.Sgather;
import com.guigu.xiaowenbo.pojo.Sgatherdetails;
import com.guigu.xiaowenbo.service.SgatherService;
import com.guigu.xiaowenbo.service.SgatherdetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class SgatherdetailsController {
    @Autowired
    SgatherdetailsService sgatherdetailsService;
    @Autowired
    SgatherService sgatherService;

    @RequestMapping("selectsgd")
    public ModelAndView selectsgd(Integer id, HttpSession session){
        String acc = ((Account) session.getAttribute("user")).getAccount();
        ModelAndView modelAndView = new ModelAndView();
        List<Sgatherdetails> listsgad = sgatherdetailsService.selectsgd(id);
        Sgather sgather = sgatherdetailsService.selectsgid(id);
        modelAndView.addObject("sgad",listsgad);
        modelAndView.addObject("sga",sgather);
        modelAndView.addObject("name",acc);
        modelAndView.setViewName("xiao_wen_bo/demoewfh.jsp");
        return modelAndView;
    }
    @RequestMapping("selectsgddd")
    public ModelAndView selectsgddd(Integer id, HttpSession session){
        String acc = ((Account) session.getAttribute("user")).getAccount();
        Integer num=0;
        ModelAndView modelAndView = new ModelAndView();
        List<Sgatherdetails> sgatherdetails = sgatherdetailsService.selectsgd(id);
        System.out.println(sgatherdetails.size());
        for (Sgatherdetails sgatherdetail : sgatherdetails) {
            if (sgatherdetail.getGathertag().equals("K002-2")){
                num+=1;
            }
        }
        if (num==sgatherdetails.size()){
            sgatherService.updatesgd(acc,id);
            modelAndView.setViewName("xiao_wen_bo/selectsgdd.jsp");
        }else {
            List<Sgatherdetails> listsgad = sgatherdetailsService.selectsgddd(id);
            Sgather sgather = sgatherdetailsService.selectsgid(id);
            modelAndView.addObject("sgad",listsgad);
            modelAndView.addObject("sga",sgather);
            modelAndView.setViewName("xiao_wen_bo/demoewdd.jsp");

        }
        return modelAndView;
    }
    @RequestMapping("selectsgdp")
    public ModelAndView selectsgdp(Integer parentid, String productid, HttpSession session){
        String acc = ((Account) session.getAttribute("user")).getAccount();
        ModelAndView modelAndView = new ModelAndView();
        Sgatherdetails listsgad = sgatherdetailsService.selectsgdp(parentid,productid);
        Sgather sgather = sgatherdetailsService.selectsgid(parentid);
        modelAndView.addObject("sgad",listsgad);
        modelAndView.addObject("sga",sgather);
        modelAndView.addObject("name",acc);
        modelAndView.setViewName("xiao_wen_bo/demoewdds.jsp");
        return modelAndView;
    }
    @RequestMapping("updatesgd")
    @OpLog(opModule = "出入库调度模块",operType = "入库调度",operDesc = "此方法用于入库调度")
    public String updatesgd(Integer parentid,String productid){
        sgatherdetailsService.updatesgd(parentid,productid);
        return "selectsgddd?id="+parentid;
    }
    @RequestMapping("selectsgdrs")
    public ModelAndView selectsgdrs(Integer parentid, HttpSession session){
        String acc = ((Account) session.getAttribute("user")).getAccount();
        ModelAndView modelAndView = new ModelAndView();
        List<Sgatherdetails> sgatherList = sgatherdetailsService.selectsgdrs(parentid);
        Sgather sgather = sgatherdetailsService.selectsgid(parentid);
        modelAndView.addObject("sgad",sgatherList);
        modelAndView.addObject("sga",sgather);
        modelAndView.addObject("name",acc);
        modelAndView.setViewName("xiao_wen_bo/demoewrs.jsp");
        return modelAndView;
    }
    @RequestMapping("selectsgdrssh")
    public ModelAndView selectsgdrssh(Integer parentid, HttpSession session){
        String acc = ((Account) session.getAttribute("user")).getAccount();
        Integer[] gath = (Integer[]) session.getAttribute("gath");
        ModelAndView modelAndView = new ModelAndView();
        List<Sgatherdetails> sgatherList = sgatherdetailsService.selectsgdrs(parentid);
        Sgather sgather = sgatherdetailsService.selectsgid(parentid);
        modelAndView.addObject("sgad",sgatherList);
        modelAndView.addObject("sga",sgather);
        modelAndView.addObject("ga",gath);
        modelAndView.addObject("name",acc);
        modelAndView.setViewName("xiao_wen_bo/demoewrssh.jsp");
        return modelAndView;
    }
}
